const app = getApp();
Page({

  data: {
    id:"",
    name:'',
    industry:'',
    post:'',
    keyword:'',
    start_time:'请选择入职日期',
    end_time:'请选择离职日期',
    click_button:0
  },

  onLoad: function (options) {
    var that = this;
    that.setData({
      id: options.id
    })
    that.getWorkInfo();
  },

  onShow: function () {

  },

  get_name: function(e){
    var that=this;
    that.setData({
      name:e.detail.value
    })
  },

  get_industry: function(e){
    var that=this;
    that.setData({
      industry:e.detail.value
    })
  },

  get_post: function(e){
    var that=this;
    that.setData({
      post:e.detail.value
    })
  },

  get_keyword: function(e){
    var that=this;
    that.setData({
      keyword:e.detail.value
    })
  },

  bindStartChange: function(e) {
    this.setData({
      start_time: e.detail.value
    })
  },

  bindEndChange: function(e) {
    this.setData({
      end_time: e.detail.value
    })
  },

  getWorkInfo: function(e) {
    var that = this;
    wx.request({
      url: app.globalData.domain + 'index/getWorkInfo',
      method: "POST",
      data: {
        id: that.data.id
      },
      header: {
        "Content-Type": "application/x-www-form-urlencoded"
      },
      success: (res) => {
        that.setData({
          name: res.data.info.name,
          industry: res.data.info.industry,
          post: res.data.info.post,
          keyword: res.data.info.keyword,
          start_time: res.data.info.start_time,
          end_time: res.data.info.end_time
        })
      },
    })
  },

  submit_result:function(){
    var that = this;
    if (that.data.name == '') {
      wx.showToast({
        title: '请输入公司名',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.industry  == '') {
      wx.showToast({
        title: '请输入从事行业',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.post=='') {
      wx.showToast({
        title: '请输入岗位',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.keyword=='') {
      wx.showToast({
        title: '请输入技能',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.start_time=='请选择入职日期') {
      wx.showToast({
        title: '请选择入职日期',
        icon: 'none',
        duration: 2000,
      })
    } else if (that.data.end_time=='请选择离职日期') {
      wx.showToast({
        title: '请选择离职日期',
        icon: 'none',
        duration: 2000,
      })
    } else {
      this.setData({
        click_button: 1
      })
      wx.request({
        url: app.globalData.domain + 'index/updateWork',
        method: "POST",
        data: {
          id: that.data.id,
          name: that.data.name,
          industry: that.data.industry,
          post: that.data.post,
          keyword: that.data.keyword,
          start_time: that.data.start_time,
          end_time: that.data.end_time,
          user_id: wx.getStorageSync('userinfo').id
        },
        header: {
          "Content-Type": "application/x-www-form-urlencoded"
        },
        success: function(res) {
          if (res.data.code == 0) {
            wx.showToast({
              title: res.data.message,
              icon: 'none',
              duration: 2000,
              success: function() {
                that.setData({
                  name:'',
                  industry:'',
                  post:'',
                  keyword:'',
                  start_time:'请选择入职日期',
                  end_time:'请选择离职日期',
                  click_button:0
                })
                setTimeout(() => {
                  wx.navigateBack({
                    delta: 1
                  });
                }, 1000);
              }
            })
          } else {
            wx.showToast({
              title: res.data.message,
              icon: 'none',
              duration: 2000,
              success: function() {
                that.setData({
                  name:'',
                  industry:'',
                  post:'',
                  keyword:'',
                  start_time:'请选择入职日期',
                  end_time:'请选择离职日期',
                  click_button:0
                })
              }
            })
          }
        }
      })
    }
  },

})